package tr3dtris;

import java.io.File;
import java.io.FileNotFoundException;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JFrame;
import org.ho.yaml.Yaml;
import tr3dtris.game.Game;
import tr3dtris.game.GameActions;
import tr3dtris.game.controller.Controller;
import tr3dtris.game.controller.inputMapper.DefaultInputMapper;
import tr3dtris.game.display.Display2d;
import tr3dtris.game.display.ui.LogoPanel;
import tr3dtris.game.display.ui.MainWindow;
import tr3dtris.game.persistence.Options;
import tr3dtris.game.persistence.Record;
import tr3dtris.game.persistence.RecordArray;

/**
 * Main class. Initializes the game.
 * @author Luciano Mammino <loige@hotmail.com>
 * @author Andrea Mangano <kapitan0@hotmail.it>
 * @version 0.1
 * @since 0.1
 */
public class Main
{

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args)
    {
        //generateRecords();
        loadOptions();

        //creates the main window
        JFrame w = new MainWindow(loadOptions());

        //configure the mainwindow adding onto it the default display of the game
        //w.setContentPane(game.getFirstDisplay());
        //w.setContentPane(new LogoPanel());

        //make the game window visible
        w.setVisible(true);
    }

    private static Options loadOptions()
    {
        return Options.load();
    }

    //TODO remove this test function
    private static void generateRecords()
    {
        RecordArray ra = new RecordArray();
        for(int i=0; i < 10; i++)
        {
            Record r = new Record("TREdTRIS", (int)(Math.random()* 1000));
            ra.getRecords().add(r);
        }
        ra.sort();
        try {
            Yaml.dump(ra, new File("data/records.yml"));
        } catch (FileNotFoundException ex) {
            Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

}